package com.iwop.moto.controller;

import com.iwop.moto.comm.ErrCode;
import com.iwop.moto.model.ResultModel;
import com.iwop.moto.model.SuperRecordModel;
import com.iwop.moto.service.OrderAssessService;
import com.iwop.moto.service.OrderGoodsService;
import com.iwop.moto.utils.stringUtil.SequenceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * liuwb 2016-07-29 14:01
 */
@Controller
public class OrderAssessController extends  BaseController {

    @Autowired
    private OrderAssessService orderAssessService;

    @Autowired
    private OrderGoodsService orderGoodsService;
    /**
     ***************************************
     * 功能:商品评价 - 新增
     * liuwb 2016-07-29 14:23
     * 参数: orderNo 订单号
     * 参数: goodsId 商品Id
     * 参数: userId 买家Id
     * 参数: assessLv 评价星级1~5
     * 参数: assessContent 评价内容
     * 参数: imgpath 评价配图(多图逗号隔开)
     ***************************************
     */
    @RequestMapping("/api/order/assess/add")
    @ResponseBody
    public ResultModel apiOrderAssessAdd(){
        SuperRecordModel SRModel = this.getSRModel();
        try {
            SRModel.put("sid",UUID.randomUUID().toString());
            SRModel.put("statusFlag","1");
            SRModel.put("statusTime",new Date());
            orderAssessService.insertAssess(SRModel);
            SuperRecordModel srm=new SuperRecordModel();
            srm.put("orderStatus","5");
            srm.put("orderNo",SRModel.getString("orderNo"));
            srm.put("orderStatusTime",new Date());
            orderGoodsService.upOrderStatus(srm);
            return getSucceed(ErrCode.SUCCEED);
        } catch (Exception e) {
            e.printStackTrace();
            return getErr(ErrCode.ERROR_SYSTEM);
        }
    }

    /**
     ***************************************
     * 功能:商品评价 - 获取商品的所有评价
     * liuwb 2016-07-29 14:30
     * 参数: goodsId 商品Id
     ***************************************
     */
    @RequestMapping("/api/order/assess/list")
    @ResponseBody
    public ResultModel apiOrderAssessList(){
        SuperRecordModel SRModel = this.getSRModel();
        try {
            List<SuperRecordModel> lists = orderAssessService.findOrderAssessByGoodsId(SRModel);
            return getSucceed(lists);
        } catch (Exception e) {
            e.printStackTrace();
            return getErr(ErrCode.ERROR_SYSTEM);
        }
    }

    /**
     ***************************************
     * 功能:商品评价 - 根据订单号获取评价
     * liuwb 2016-07-29 14:30
     * 参数: orderNo 订单号
     ***************************************
     */
    @RequestMapping("/api/order/assess/detail")
    @ResponseBody
    public ResultModel apiOrderAssessDetail(){
        SuperRecordModel SRModel = this.getSRModel();
        try {
            SRModel = orderAssessService.findOrderAssessDetail(SRModel);
            return getSucceed(SRModel);
        } catch (Exception e) {
            e.printStackTrace();
            return getErr(ErrCode.ERROR_SYSTEM);
        }
    }









}
